package netWork;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Homework01Client {

    public static void main(String[] args) throws IOException {
        try (Socket socket = new Socket("127.0.0.1", 9999);
             Scanner scanner = new Scanner(System.in);
             BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
             BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))
             ) {
         while (true){
             System.out.println("->");
             String request = scanner.next();
             writer.write(request);
             writer.newLine();
             writer.flush();
             String response = reader.readLine();
             if(response.equals("0")){
                 System.out.println("客户端退出");
                 break;
             }
             System.out.printf("[%s %d], req :%s  resp :%s\n", socket.getInetAddress().getHostAddress(), socket.getPort(), request, response);
            }
         }
    }
}
